package godau.fynn.bandcampdirect.extractor.converter;

import godau.fynn.bandcampdirect.model.Album;
import godau.fynn.bandcampdirect.model.Artist;
import godau.fynn.bandcampdirect.model.RowViewDisplayable;
import godau.fynn.bandcampdirect.model.Track;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;

public class SearchConverter {

    public static RowViewDisplayable toRowViewDisplayable(InfoItem result) {
        if (result instanceof StreamInfoItem) {
            return new Track(
                    result.getName(),
                    result.getUrl(),
                    result.getThumbnailUrl(),
                    ((StreamInfoItem) result).getUploaderName()
            );
        } else if (result instanceof PlaylistInfoItem) {
            return new Album(
                    result.getName(),
                    ((PlaylistInfoItem) result).getUploaderName(),
                    result.getUrl(),
                    result.getThumbnailUrl()
            );
        } else if (result instanceof ChannelInfoItem) {
            return new Artist(
                    result.getName(),
                    result.getUrl(),
                    result.getThumbnailUrl()
            );
        } else return null;
    }
}
